package pdai.a2_多线程;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;

public class TestThread2 extends Thread {
    private String url;
    private String name;

    public TestThread2(String url, String name) {
        this.url = url;
        this.name = name;
    }

    @Override
    public void run() {
        webdownloader webdownloader=new webdownloader();
        webdownloader.download(url,name);
        System.out.println("下载了"+name+"文件");
    }

    public static void main(String[] args) {
        TestThread2 t1=new TestThread2("https://iconfont.alicdn.com/t/079428b9-fba2-4450-8d9e-3e77beb7148f.png@200h_200w.jpg","aaaaaaa.jpg");
        TestThread2 t2=new TestThread2("https://iconfont.alicdn.com/t/1570850261949.png@200h_200w.jpg","bbbbbbb.jpg");
        TestThread2 t3=new TestThread2("https://iconfont.alicdn.com/t/4b8e539e-521f-427d-a83e-c8b94a2aab37.jpeg@200h_200w.jpg","ccccccc.jpg");

        t1.start();
        t2.start();
        t3.start();

    }
}
//下载器
class  webdownloader{

    public void  download(String url,String name){
        try {
            FileUtils.copyURLToFile(new URL(url),new File(name));
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("io异常，download方法异常");
        }
    }
}
